import os, sys
import pymysql
import django
pymysql.install_as_MySQLdb()
# 手动调用django.setup()
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pcs_app.settings")# project_name 项目名称
django.setup()

from mqtt.message_handler import MessageHandler
from mqtt.mqtt_manage import MqttManager, message_queue

mqttManager = MqttManager("124.222.234.138", "wyl_pcs", "1234rewq")


def startMQTTTask():
    print("start mqtt subscribe")
    mqttManager.on_subscribe("device01/#")
    # mqttManager.mqtt_publish("device01/01", text="发布一个消息")
    messageHandler = MessageHandler(message_queue)
    messageHandler.daemon = True
    messageHandler.start()


startMQTTTask()
